package com.example.zsf.network;

import com.example.zsf.base.ZSFGlobal;
import com.example.zsf.model.UserModel;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class HeaderInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();

        if (!ZSFGlobal.checkLogoutStatus(null)) {
            UserModel userModel = ZSFGlobal.getUserModel();
            Request request = original.newBuilder()
                    .header("x-user-id", userModel.getId())
                    .header("x-user-token", userModel.getToken())
                    .method(original.method(), original.body())
                    .build();

            return chain.proceed(request);
        }

        return chain.proceed(original);
    }
}
